﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for LoggEntryDAL
/// </summary>
public class LoggEntryDAL : DALBase
{
    public void NewLoggEntry(LoggEntry loggEntry)
    {
        using (SqlConnection conn = CreateConnection()) // using för att den alltid ska stängas sen.
        {
            try
            {                // namnet på den lagrade proceduren mellan ""
                var cmd = new SqlCommand("dbo.usp_CreateLoggEntry", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@LoggID", SqlDbType.Int, 8).Direction = ParameterDirection.Output;

                cmd.Parameters.Add("@Details", SqlDbType.VarChar, 500).Value = loggEntry.Details;
                cmd.Parameters.Add("@Ip", SqlDbType.VarChar, 20).Value = loggEntry.IP;


                conn.Open();
                cmd.ExecuteNonQuery();
                loggEntry.LoggID = (Int64)cmd.Parameters["@LoggID"].Value;
            }
            catch
            {
                //throw new ApplicationException("An error has occured in the data access layer.");
            }

        }
    }


	public LoggEntryDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}